package com.xkdx.caipiao.setup;

import java.util.HashMap;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.xkdx.caipiao.R;
import com.xkdx.caipiao.ThreadActivity;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.presistence.identity.IdentityAction;
import com.xkdx.caipiao.presistence.identity.IdentityInfo;
import com.xkdx.caipiao.presistence.identity.IdentityModule;
import com.xkdx.caipiao.presistence.identity.IdentityPresistence;
import com.xkdx.caipiao.presistence.login.LoginInfo;
import com.xkdx.caipiao.statics.IConstants;
import com.xkdx.caipiao.util.Md5Utils;
import com.xkdx.caipiao.util.SharePrefenceUtil;

public class ShowIdentityInfo extends ThreadActivity {

	private ImageView back;
	private TextView tv_nickname, tv_identitycode, tv_realname, tv_phonenumber;
	private SharePrefenceUtil su;
	private IdentityAction action;
	private IdentityModule module;
	private IdentityPresistence presistence;
	private IdentityInfo info;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.setup_identity_info_caipiao);
		su = new SharePrefenceUtil(getApplicationContext(),
				SharePrefenceUtil.USERINFO);
		findView();

		startThread();

	}

	private void findView() {
		back = (ImageView) findViewById(R.id.back);
		tv_nickname = (TextView) findViewById(R.id.tv_nickname);
		tv_identitycode = (TextView) findViewById(R.id.tv_identitycode);
		tv_realname = (TextView) findViewById(R.id.tv_realname);
		tv_phonenumber = (TextView) findViewById(R.id.tv_phonenumber);
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {
		if (result.containsKey("0")) {
			info = module.info;
			if (info != null) {
				tv_nickname.setText(su.getUserInfo().getUser_nickname());
				tv_identitycode.setText(info.getIdcard());
				tv_realname.setText(info.getRealname());
				tv_phonenumber.setText(info.getPhone());
			}

		}
	}

	@Override
	public void startThread() {
		String id = su.getUserInfo().getId();
		String token = su.getUserInfo().getLogintoken();
		String md5 = id+token+IConstants.key;
		String signcode = Md5Utils.md5(md5);
		action = new IdentityAction(id, token,signcode);
		module = new IdentityModule(ShowIdentityInfo.this);
		presistence = new IdentityPresistence(ShowIdentityInfo.this);
		presistence.setActitons(action);
		presistence.setModule(module);
		presistence.execute();
	}

	@Override
	public void onBackClick(View view) {
		// TODO Auto-generated method stub

	}

}
